﻿using log4net;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ZSZ.Service.Entity;

namespace ZSZ.Service
{
    public class ZSZDBcontext : DbContext
    {
        private ILog logger = LogManager.GetLogger(typeof(ZSZDBcontext));
        public ZSZDBcontext() : base("name=conn")
        {
            //策略三：模型更改时重新创建数据库
            Database.SetInitializer<ZSZDBcontext>(null);
            //如果发生数据库异常，记录日志
            this.Database.Log = (sql) => { logger.DebugFormat("EF正在执行：{0}", sql); };
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
        }
        public DbSet<AdminUserEntity> AdminUsers { get; set; }
        public DbSet<AttachmentEntity> Attachments { get; set; }
        public DbSet<CityEntity> Cities { get; set; }
        public DbSet<CommunitiesEntity> Communities { get; set; }
        public DbSet<HouseAppointmentEntity> HouseAppointments { get; set; }
        public DbSet<HouseEntity> Houses { get; set; }
        public DbSet<HousePicEntity> HousePics { get; set; }
        public DbSet<IdNamesEntity> IdNames { get; set; }
        public DbSet<PermissionEntity> Permissions { get; set; }
        public DbSet<RegionEntity> Regions { get; set; }
        public DbSet<RoleEntity> Roles { get; set; }
        public DbSet<SettingEntity> Settings { get; set; }
        public DbSet<UserEntity> Users { get; set; }
        public DbSet<AdminLogEntity> AdminLogs { get; set; }
    }
}
